<#--  
aoColNum 列的数量 
collist 设置每个列详细参数，优先选择

eg:
<@tablePage aoColNum=10 collist='[{ "bSortable": false },{ "bSortable": false },{ "bSortable": false },{ "bSortable": false },{ "bSortable": false },null,{ "bSortable": false },null,{ "bSortable": false },{ "bSortable": false }]'/>
-->
<#macro tablepage colnum=10 collist="">
<script type="text/javascript">
    var BookPage = function () {

        return {
            //main function to initiate the module
            init: function () {

                if (!jQuery().dataTable) {
                    return;
                }

                // begin table
                $('#sample_1').dataTable({
                    "bFilter": true,
                    "bScrollCollapse": true,
                    "scrollY": "20px",
                    "bSearchable": false,
                    "bDestroy": true,
                    "bServerSide": true,
//                "sServerMethod": 'GET',
                    "sAjaxSource": 'books/displayAll',
                    "sAjaxDataProp": 'content',
                    "bLengthChange": true,
                    "bInfo": true,
                    "bPaginate": true,
                    "bInfo": true,
                    "fnServerData": function (sSource, aDataSet, fnCallback) {
                        $.ajax({
                            "dataType": 'json',
                            "type": "GET",
                            "url": sSource,
                            "data": aDataSet,
                            "success": function (resp) {
                                fnCallback(resp);
                            }
                        });
                    },
                    "aoColumns": [
                        {
                            "mData": "id",
                            "mRender": function (data, type, row, meta) {
                                return '<input type="checkbox" class="checkboxes" value="' + data + '" />'
                            }
                        },
                        {
                            "mData": "bookname",
                            "bSortable": false,
                            "bSortable": true,
                        },
                        {"mData": "rfid"},
                        {"mData": "barcode"},
                        {"mData": "createDate"},
                        {"mData": "updateDate"},
                        {"mData": "isDeleted"},
                        {"mData": "remark"},
                        {
                            "mData": "id",
                            "mRender": function (data, type, row, meta) {
                                return '<span class=""><a class="edit" href="/sys/books/edit/' + data + '">编辑</a></span>\n' +
                                        '                                <span class=""><a class="edit" href="javascript:void(0);"\n' +
                                        '                                                  onclick="book.del(\'' + data + '\');">删除</a></span>'
                            }
                        }
                    ],
                    "aLengthMenu": [
                        [5, 10, 20, 50],
                        [5, 10, 20, 50] // change per page values here
                    ],
                    // set the initial value
                    //${colnum},
                    "iDisplayLength": 5,
                    "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
//                "sPaginationType": "",
                    "oLanguage": {
                        "sLengthMenu": "_MENU_ records per page",
                        "oPaginate": {
                            "sFirst": "第一页",
                            "sPrevious": " 上一页 ",
                            "sNext": " 下一页 ",
                            "sLast": " 最后一页 "
                        }
                    },
                    "aoColumnDefs": [{
                        'bSortable': false,
                        'aTargets': [0]
                    }
                    ]
                });

                jQuery('#sample_1 .group-checkable').change(function () {
                    var set = jQuery(this).attr("data-set");
                    var checked = jQuery(this).is(":checked");
                    jQuery(set).each(function () {
                        if (checked) {
                            $(this).attr("checked", true);
                        } else {
                            $(this).attr("checked", false);
                        }
                    });
                    jQuery.uniform.update(set);
                });

                jQuery('#sample_1_wrapper .dataTables_filter input').addClass("m-wrap medium"); // modify table search input
                jQuery('#sample_1_wrapper .dataTables_length select').addClass("m-wrap small"); // modify table per page dropdown
                //jQuery('#sample_1_wrapper .dataTables_length select').select2(); // initialzie select2 dropdown

            }

        };

    }();


    var DevicePage = function () {

        return {
            //main function to initiate the module
            init: function () {

                if (!jQuery().dataTable) {
                    return;
                }

                // begin table
                $('#sample_1').dataTable({
                    "bFilter": true,
                    "bScrollCollapse": true,
                    "bDestroy": true,
                    "bServerSide": true,
//                "sServerMethod": 'GET',
                    "sAjaxSource": 'books/displayAll',
                    "sAjaxDataProp": 'content',
                    "bLengthChange": true,
                    "bInfo": true,
                    "bPaginate": true,
                    "bInfo": true,
                    "fnServerData": function (sSource, aDataSet, fnCallback) {
                        $.ajax({
                            "dataType": 'json',
                            "type": "GET",
                            "url": sSource,
                            "data": aDataSet,
                            "success": function (resp) {
                                fnCallback(resp);
                            }
                        });
                    },
                    "aoColumns": [
                        {
                            "mData": "id",
                            "mRender": function (data, type, row, meta) {
                                return '<input type="checkbox" class="checkboxes" value="' + data + '" />'
                            }
                        },
                        {"mData": "sysid"},
                        {"mData": "name"},
                        {"mData": "key"}
                    ],
                    "aLengthMenu": [
                        [5, 10, 20, -1],
                        [5, 10, 20, "All"] // change per page values here
                    ],
                    // set the initial value
                    //${colnum},
                    "iDisplayLength": 5,
                    "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
//                "sPaginationType": "",
                    "oLanguage": {
                        "sLengthMenu": "_MENU_ records per page",
                        "oPaginate": {
                            "sFirst": "第一页",
                            "sPrevious": " 上一页 ",
                            "sNext": " 下一页 ",
                            "sLast": " 最后一页 "
                        }
                    },
                    "aoColumnDefs": [{
                        'bSortable': false,
                        'aTargets': [0]
                    }
                    ]
                });

                jQuery('#sample_1 .group-checkable').change(function () {
                    var set = jQuery(this).attr("data-set");
                    var checked = jQuery(this).is(":checked");
                    jQuery(set).each(function () {
                        if (checked) {
                            $(this).attr("checked", true);
                        } else {
                            $(this).attr("checked", false);
                        }
                    });
                    jQuery.uniform.update(set);
                });

                jQuery('#sample_1_wrapper .dataTables_filter input').addClass("m-wrap medium"); // modify table search input
                jQuery('#sample_1_wrapper .dataTables_length select').addClass("m-wrap small"); // modify table per page dropdown
                //jQuery('#sample_1_wrapper .dataTables_length select').select2(); // initialzie select2 dropdown

            }

        };

    }();
</script>
</#macro>
